package com.zdx.yswl.ui.task;

import java.io.IOException;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import com.zdx.yswl.Constant;
import com.zdx.yswl.asynctask.BaseHttpTask;
import com.zdx.yswl.base.KException;
import com.zdx.yswl.ui.bean.DetailedInforBean;
import com.zdx.yswl.ui.bean.PictruesBean;
import com.zdx.yswl.ui.exception.JSONParseException;
import com.zdx.yswl.ui.exception.NetworkException;
import com.zdx.yswl.ui.exception.NoDataException;
import com.zdx.yswl.ui.http.HttpUtils;

public class AllPictureTask extends BaseHttpTask<Map<String, Object>, Void, Object> {

	
	public AllPictureTask(int taskId, com.zdx.yswl.http.KAsyncTask.TaskDelegate delegate) {
		super(taskId, delegate);
	}

	
	@Override
	protected Object doInBackground(Map<String, Object>... params) {
		
		String str = "";
		try {
			str = HttpUtils.sendPostMethod4Path(Constant.ConfigNet.get_all_picture, params[0], "utf-8");
		} catch (ClientProtocolException e) {
			e.printStackTrace();
			return new NetworkException();
		} catch (IOException e) {
			e.printStackTrace();
			return new NetworkException();
		}
		
		return str;
	}


	@Override
	protected void onPostExecute(Object result) {
		super.onPostExecute(result);
		PictruesBean bean = null;
		try {
			JSONObject json = new JSONObject(result+"");
			int __returnCode = json.getInt("status");
			if (__returnCode != 0) {
				if (this.getDelegate() != null) {
					this.getDelegate() .faild_TaskDelegate(super.getTaskId(), new KException(json.getString("msg")));
				}
				return;
			}
			bean = PictruesBean.getBean4JSON(json.getJSONObject("data"));
			if (bean == null) {
				throw new NoDataException();
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
			if (super.getDelegate() != null) {
				super.getDelegate().faild_TaskDelegate(super.getTaskId(), new JSONParseException());
			}
			return;
		} catch (NoDataException e) {
			e.printStackTrace();
			if (super.getDelegate() != null) {
				super.getDelegate().faild_TaskDelegate(super.getTaskId(), new NoDataException());
			}
			return;
		}
		
		this.getDelegate().success_TaskDelegate(super.getTaskId(), bean);
		
	}
}
